package br.com.skolar.client.framework;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.DomEvent;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;

public abstract class ButtonHandler implements ClickHandler, KeyUpHandler {
	protected abstract void onEvent(DomEvent e);
	
	@Override
	public void onClick(ClickEvent event) {
		onEvent(event);
	}

	@Override
	public void onKeyUp(KeyUpEvent event) {
		switch (event.getNativeKeyCode()) {
		case ' ':
		case KeyCodes.KEY_ENTER:
			onEvent(event);
		}
	}
}